function stringify(value, key) {
    let typ = Object.prototype.toString.call(value).slice(8, -1)
    let itemStr
    switch (typ) {
        case 'Null':
            itemStr = null
            break
        case 'Number':
            itemStr = String(value)
            break
        case 'String':
            itemStr = `"${value}"`
            break
        case 'Array':
            let strArr = []
            value.forEach(arrayValue => {
                strArr.push(stringify(arrayValue))
            })
            itemStr = `[${strArr.join(',')}]`
            break
        case 'Object':
            let objArr = []
            Object.keys(value).forEach(objKey => {
                objArr.push(stringify(value[objKey], objKey))
            })
            itemStr = `{${objArr.join(',')}}`
            break
        default:
            console.error('err type')
    }
    if (key) {
        return `"${key}":${itemStr}`
    } else {
        return itemStr
    }
}

let test1 = {
    // foo1: null,
    foo: 'bar',
    bar1: 1024,
    bar: [1, 2, "124"],
    baz: {
        foo: 'bar',
        bar: [
            {
                foo: 'bar'
            },
            2
        ]
    }
}

console.dir(stringify(test1))
